﻿
Namespace PL.MESSDK
    Public Class ItemMasterSpecificationRevisionDetail_PL
        Inherits PLBase
        Implements IPLProcess

        Public Property ItemMasterID_FK As Guid?
        Public Property ItemMasterSpecRevID_FK As Guid?

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Public Sub New()
            MyBase.New()
        End Sub

        Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs) Handles MetaDataTable.OnRowUpdating
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Shared Sub RRDetail_Limite(aDataRow As DataRow)

            'TODO...
            Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

            Try
                sqlcmd = MetaQuery.GetSPCmdByMetaName("IMSRDetail_Revise")
                'Match les param[etre de la SP avec les colonne de la grilles
                For Each pr As System.Data.SqlClient.SqlParameter In sqlcmd.Parameters
                    If aDataRow.Table.Columns.Contains(pr.SourceColumn) Then
                        sqlcmd.Parameters(pr.ParameterName).Value = aDataRow(pr.SourceColumn)
                    End If
                Next
                sqlcmd.ExecuteNonQuery()
                'Fin TODO
            Catch sqlex As System.Data.SqlClient.SqlException

            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Dispose()
                End If
            End Try

        End Sub

        Public Shared Sub IMRevision_Copy(ByVal ItemMasterRevId As Guid, ByVal ItemMasterID_FK As Guid)

            'TODO...
            Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

            Try
                sqlcmd = MetaQuery.GetSPCmdByMetaName("IMRevision_CopyFrom")
                'Match les param[etre de la SP avec les colonne de la grilles

                sqlcmd.Parameters("@ItemMasterRevId").Value = ItemMasterRevId
                sqlcmd.Parameters("@ItemMasterID_FK").Value = ItemMasterID_FK

                sqlcmd.ExecuteNonQuery()
                'Fin TODO
            Catch sqlex As System.Data.SqlClient.SqlException

            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Dispose()
                End If
            End Try

        End Sub

        Public Shared Sub IMSRevision_Copy(ByVal ItemMasterSpecRevID As Guid, ByVal ItemMasterRevId As Guid)
            'TODO...
            Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

            Try
                sqlcmd = MetaQuery.GetSPCmdByMetaName("IMSRevision_CopyFrom_EXP")

                sqlcmd.Parameters("@ItemMasterSpecRevID").Value = ItemMasterSpecRevID
                sqlcmd.Parameters("@ItemMasterRevId").Value = itemMasterRevId

                sqlcmd.ExecuteNonQuery()
                'Fin TODO
            Catch sqlex As System.Data.SqlClient.SqlException

            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Dispose()
                End If
            End Try

        End Sub

        Public Function BatchRecords(dataRow() As System.Data.DataRow) As Boolean Implements IPLProcess.BatchRecords
            Return True
        End Function

        Public Function CurrentRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.CurrentRecord
            Return True
        End Function

        Public Function NewRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.NewRecord
            'Si on arrive d'un TreeList...
            If ItemMasterID_FK IsNot Nothing Then
                dataRow("ItemMasterID_FK") = ItemMasterID_FK
            End If

            If IsDBNull(dataRow("Compulsory")) Then
                dataRow("Compulsory") = 0
            End If

            If IsDBNull(dataRow("CompulsaryRep")) Then
                dataRow("CompulsaryRep") = 0
            End If

            If IsDBNull(dataRow("Repetition")) Then
                dataRow("Repetition") = 1
            End If

            If ItemMasterSpecRevID_FK IsNot Nothing Then
                dataRow("ItemMasterSpecRevID_FK") = ItemMasterSpecRevID_FK
            End If


            dataRow("BegRev") = 0
            dataRow("EndRev") = 999

            dataRow("ItemMasterSpecID") = Guid.NewGuid
            dataRow("ItemMasterSpecRevDetailID") = Guid.NewGuid
            
            Return True
        End Function
    End Class
End Namespace
